//
//  JCClubInfoMessageCell.m
//  SquashSpark
//
//  Created by 郭吉成 on 2017/11/22.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "JCClubInfoMessageCell.h"
#import "JCClubMessageModel.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "SQActionSheetView.h"
#import "JCClubApi.h"
#import "WSProgressHUD.h"

@interface JCClubInfoMessageCell()

@property (nonatomic, strong) JCClubMessageModel *model;
@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@end

@implementation JCClubInfoMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _headerImageView.layer.cornerRadius = 20;
    _headerImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    _headerImageView.layer.borderWidth = 1.5;
    
    UIButton *reportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [reportBtn setImage:[UIImage imageNamed:@"club_menu_list_message"] forState:UIControlStateNormal];
    reportBtn.frame = CGRectMake(kYFScreenWidth-45, 8, 45, 45);
    [self addSubview:reportBtn];
    [reportBtn addTarget:self action:@selector(reportAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setMessageModel:(JCClubMessageModel *)model{
    _model = model;
    [_headerImageView sd_setImageWithURL:model.icon placeholderImage:kHeaderPlaceholdImage];
    _nameLabel.text = model.userName;
    _timeLabel.text = model.creatTime;
    _contentLabel.text = model.content;
}

- (void)reportAction{
    __weak typeof(self)weakSelf = self;
    SQActionSheetView *sheetView = [[SQActionSheetView alloc] initWithTitle:nil buttons:@[@"Report",@"Cancel"] colors:@[[UIColor blackColor],[UIColor blackColor]] buttonClick:^(SQActionSheetView *sheetView, NSInteger buttonIndex) {
        if (buttonIndex == 0) {
            [weakSelf reportAction:_model.messageID spotterIDType:SpotterIDTypeMessage];
        }
    }];
    [sheetView showView];
}

//举报动作
- (void)reportAction:(NSString *)reportID spotterIDType:(SpotterIDType) spotterIDType{
    __weak typeof(self)weakSelf = self;
    NSArray *buttonStrs = @[@"I don't like it",
                            @"It is spam",
                            @"It contains sensitive information",
                            @"It is insulting and harmful",
                            @"Cancel"];
    NSArray *colors = @[[UIColor blackColor],[UIColor blackColor],[UIColor blackColor],[UIColor blackColor],[UIColor blackColor],[UIColor blackColor]];
    SQActionSheetView *reportSheet = [[SQActionSheetView alloc]initWithTitle:@"Select the reason for report" buttons:buttonStrs colors:colors buttonClick:^(SQActionSheetView *sheetView, NSInteger buttonIndex) {
        if (buttonIndex < 4) {
            [weakSelf spotterAction:buttonIndex+1 spotterID:reportID spotterIDType:spotterIDType];
        }
    }];
    [reportSheet showView];
}

- (void)spotterAction:(SpotterTopicType)spotterType
            spotterID:(NSString *)spotterID
        spotterIDType:(SpotterIDType) spotterIDType{

    [JCClubApi spotterWithID:spotterID spotterIDType:spotterIDType spotterType:spotterType complete:^(NSError *error) {
        if (error) {
            [WSProgressHUD showErrorWithStatus:error.domain];
        }else{
            [WSProgressHUD showSuccessWithStatus:@"Thanks!"];
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [WSProgressHUD dismiss];
        });
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
